﻿using furion.blog.Domain.MySQL;
using furion.blog.Domain.Shared.Dto.Menu;
using furion.blog.Domain.Shared.Enum;
using furion.blog.Domain.Shared.Vo.Menu;
using Furion.DependencyInjection;
using Mapster;
using MapsterMapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace furion.blog.Application.CustomMapper
{
    public class MenuMapper : Mapper, IRegister, ISingleton
    {
        public void Register(TypeAdapterConfig config)
        {
            //dto 转 po
            config.ForType<MenuTreeNodeDto,Menu>()
            //.IgnoreAttribute()
            .Map(dest => dest.MenuId, source => source.Id)
            .Map(dest => dest.Component, source => source.Component)
            .Map(dest=>dest.MenuName,source=>source.Name)
            .Map(dest => dest.Redirect, source => source.Redirect)
            .Map(dest => dest.PageTitle, source => source.Name)
            .Map(dest => dest.MenuKey, source => source.Key)
            .Map(dest => dest.Icon, source => source.Icon)
            .Map(dest => dest.Pid, source => source.Pid)
            .Map(dest => dest.Hidden, source => source.Hidden? YesOrNoEnum.Yes.ToString():YesOrNoEnum.No.ToString())
            .Map(dest => dest.KeepAlive, source => source.KeepAlive ? YesOrNoEnum.Yes.ToString() : YesOrNoEnum.No.ToString())
            .Map(dest => dest.Path, source => source.Path)
            .IgnoreNonMapped(true);


            //po 转 vo
            config.ForType<Menu,DashboardMenuVO>()
                .Map(dest=>dest.Id,source=>source.MenuId)
                .Map(dest => dest.Name, source => source.MenuName)
                .Map(dest => dest.Pid, source => source.Pid)
                .Map(dest => dest.Id, source => source.MenuId)
                .Map(dest => dest.Hidden, source => source.Hidden == YesOrNoEnum.Yes.ToString()?true:false)
                .Map(dest=>dest.Key,source=>source.MenuKey)
                .Map(dest => dest.Path, source => source.Path)
                .Map(dest => dest.Icon, source => source.Icon)
                .Map(dest => dest.Redirect, source => source.Redirect)
                .Map(dest => dest.Component, source => source.Component)
                .IgnoreNonMapped(true);

        }
    }
}
